package com.pactera.miyuangroup.controller.web;

import com.pactera.miyuangroup.service.*;
import com.pactera.miyuangroup.util.Date;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import com.pactera.miyuangroup.vo.response.VoidResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 米源数据同步接口
 *
 * @author Wangwu
 * @create 2018-07-06 下午8:48
 **/
@Api(description = "米源数据同步接口")
@RestController
@RequestMapping("miyuan")
@Slf4j
public class SyncMiyuanController {


    @Autowired
    private GoodsClassificationService goodsClassificationService;
    @Autowired
    private GoodsInfoService goodsInfoService;
    @Autowired
    private LoginUserService loginUserService;
    @Autowired
    private OrganizationStructureService organizationStructureService;
    @Autowired
    private VehicleInfoService vehicleInfoService;
    @Autowired
    private VendorInfoService vendorInfoService;
    @Autowired
    private VendorPassagewayService vendorPassagewayService;


    @ApiOperation(value = "同步组织结构", notes = "同步组织结构")
    @RequestMapping(value = "/syncInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncOrgInfo() {
        boolean flg = organizationStructureService.syncMiyuanOrgInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    /**
     * 同步用户
     *
     * @return
     */
    @ApiOperation(value = "同步用户", notes = "同步用户")
    @RequestMapping(value = "/syncUserInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncUserInfo() {
        boolean flg = loginUserService.syncMiyuanUserInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步商品", notes = "同步商品")
    @RequestMapping(value = "/syncGoodsInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncGoodsInfos() {
        boolean flg = goodsInfoService.syncGoodsInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步商品分类", notes = "同步商品分类")
    @RequestMapping(value = "/syncGoodsInfoClassificationInfos", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncGoodsClassificationInfos() {
        boolean flg = goodsClassificationService.syncMiyuanGoodsClassificationInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步车辆信息", notes = "同步车辆信息")
    @RequestMapping(value = "/syncVehicleInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncVehicleInfo() {
        boolean flg = vehicleInfoService.syncMiyuanVehicleInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }


    @ApiOperation(value = "同步售货机货道信息【暂时不使用】", notes = "同步售货机货道信息")
    @RequestMapping(value = "/syncVendorPassagewayInfo", method = RequestMethod.GET)
    private ResultModel<VoidResponse> syncVendorPassagewayInfo() {
        boolean flg = vendorPassagewayService.syncMiyuanVendorPassagewayInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步售货机货道信息【增量】", notes = "同步售货机货道信息")
    @RequestMapping(value = "/syncVendorPassagewayInfoZl", method = RequestMethod.GET)
    private ResultModel<VoidResponse> syncVendorPassagewayInfoZl(String date) {
        vendorPassagewayService.syncMiyuanVendorPassagewaySchedulerInfo(Date.parseDate("date"));
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步售货机货道信息初始化", notes = "同步售货机货道信息初始化")
    @RequestMapping(value = "/initialization", method = RequestMethod.GET)
    private ResultModel<VoidResponse> Initialization() {
        vendorPassagewayService.excelImport();
        return ResultModel.ok();
    }

    @ApiOperation(value = "同步售货机", notes = "同步售货机")
    @RequestMapping(value = "/syncVendorInfo", method = RequestMethod.GET)
    private ResultModel<VoidResponse> syncVendorInfo() {
        boolean flg = vendorInfoService.syncMiyuanVenderInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }
}
